#define _CRT_SECURE_NO_WARNINGS 1
//offsetof, 写一个宏，计算结构体中某变量相对于首地址的偏移
//size_t offsetof(structName, memberName);
//结构体名     成员名
//offsetof(struct S, name);
//计算结构体中某变量相对于首地址的偏移

#include<stdio.h>
#include<stddef.h>
struct S
{
	int a;
	char b;
	double c;
};

#define Offsetof(st_type,mem_name) ((size_t)&(((st_type*)0)->mem_name))
//假设结构体从地址0开始，则结构体成员的地址就是偏移量
int main()
{	
	printf("%d\n", Offsetof(struct S, a));
	printf("%d\n", Offsetof(struct S, b));
	printf("%d\n", Offsetof(struct S, c));
	//printf("%d\n", offsetof(struct S, a));
	//printf("%d\n", offsetof(struct S, b));
	//printf("%d\n", offsetof(struct S, c));
}
